package com.ruoyi.biz.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.biz.mapper.BizCourseMapper;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.biz.domain.BizCourse;
import com.ruoyi.biz.service.IBizCourseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程Controller
 * 
 * @author lhb
 * @date 2025-02-02
 */
@RestController
@RequestMapping("/biz/course")
public class BizCourseController extends BaseController
{
    @Autowired
    private IBizCourseService bizCourseService;

    @Resource
    private BizCourseMapper courseMapper;

    /*
    * 根据当前登录用户查询课程列表
    * */
    @GetMapping("/myList")
    public AjaxResult getMyList(){
        Long loginId = SecurityUtils.getLoginUser().getUserId();
        List<BizCourse> bizCourses = courseMapper.selectByTeacherId(loginId);
        return AjaxResult.success(bizCourses);
    }

    /**
     * 查询课程列表
     */
    @PreAuthorize("@ss.hasPermi('biz:course:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizCourse bizCourse)
    {
        startPage();
        List<BizCourse> list = bizCourseService.selectBizCourseList(bizCourse);
        return getDataTable(list);
    }

    /**
     * 导出课程列表
     */
    @PreAuthorize("@ss.hasPermi('biz:course:export')")
    @Log(title = "课程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCourse bizCourse)
    {
        List<BizCourse> list = bizCourseService.selectBizCourseList(bizCourse);
        ExcelUtil<BizCourse> util = new ExcelUtil<BizCourse>(BizCourse.class);
        util.exportExcel(response, list, "课程数据");
    }

    /**
     * 获取课程详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:course:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizCourseService.selectBizCourseById(id));
    }

    /**
     * 新增课程
     */
    @PreAuthorize("@ss.hasPermi('biz:course:add')")
    @Log(title = "课程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCourse bizCourse)
    {
        return toAjax(bizCourseService.insertBizCourse(bizCourse));
    }

    /**
     * 修改课程
     */
    @PreAuthorize("@ss.hasPermi('biz:course:edit')")
    @Log(title = "课程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCourse bizCourse)
    {
        return toAjax(bizCourseService.updateBizCourse(bizCourse));
    }

    /**
     * 删除课程
     */
    @PreAuthorize("@ss.hasPermi('biz:course:remove')")
    @Log(title = "课程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizCourseService.deleteBizCourseByIds(ids));
    }
}
